package com.neuedu.shixun.hospital2.controller;
import com.neuedu.shixun.hospital2.entity.PingLun;
import com.neuedu.shixun.hospital2.entity.PingLun2;
import com.neuedu.shixun.hospital2.service.PingLunService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/pinglun")
@CrossOrigin
public class PingLunController {
    @Autowired
    private PingLunService pingLunService;
    @GetMapping("getAll")
    public List<PingLun2> getAll(){
     List<PingLun> list= pingLunService.getAll();
     return pingLunService.getAll2(list);
    }
    @PostMapping("update")
    public PingLun update(@RequestBody PingLun pingLun){
       return pingLunService.update(pingLun.getPid(),pingLun.getPStatus());
    }
    @GetMapping("/findByPage")
    public Page<PingLun2> findByPage(@RequestParam(value = "pageCode" ,defaultValue = "0")int pageCode,
                                     @RequestParam(value = "pageSize" ,defaultValue = "3")int pageSize) {
        log.info("评论页码"+pageCode);
        log.info("评论条数"+pageSize);
        Page<PingLun2> pingLun2Page= pingLunService.findByPage(pageCode,pageSize);
        return pingLun2Page;
    }
    @GetMapping("getTotalNum")
    public Integer getTotalNum(){
      return  pingLunService.getAll().size();
    }
}
